﻿Public Class frmThem_CapNhatNhaCungCap
    Public _status As String
    Public _id As Integer
    Private Sub frmThem_CapNhatNhaCungCap_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        If _status = "Them" Then
            Me.Text = "Thêm nhà cung cấp"
            btnThem_CapNhat.Text = "Thêm"
        ElseIf _status = "CapNhat" Then
            Me.Text = "Cập nhật nhà cung cấp"
            btnThem_CapNhat.Text = "Cập nhật"
        End If

    End Sub

    Private Sub btnThem_CapNhat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThem_CapNhat.Click
        If txtNhaCungCap.Text = "" Or txtDiaChi.Text = "" Or txtSoDienThoai.Text = "" Then
            MessageBox.Show("Bạn phải điền đủ thông tin!", "", MessageBoxButtons.OK, MessageBoxIcon.None)
            Return
        ElseIf _status = "Them" Then
            Try
                Dim _ncc = New NhaCungCap()
                _ncc.m_strTen = txtNhaCungCap.Text
                _ncc.m_strDiaChi = txtDiaChi.Text
                _ncc.m_strSoDienThoai = txtSoDienThoai.Text
                NhaCungCapDAO.ThemNhaCungCap(_ncc)
                MessageBox.Show("Thêm thành công!", "", MessageBoxButtons.OK)
                me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        ElseIf _status = "CapNhat" Then
            Try
                Dim _ncc = New NhaCungCap()
                _ncc.m_intID = _id
                _ncc.m_strTen = txtNhaCungCap.Text
                _ncc.m_strDiaChi = txtDiaChi.Text
                _ncc.m_strSoDienThoai = txtSoDienThoai.Text
                NhaCungCapDAO.CapNhatNhaCungCap(_ncc)
                MessageBox.Show("Cập nhật thành công!", "", MessageBoxButtons.OK)
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub btnThoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThoat.Click
        me.Close()
    End Sub

    Private Sub txtSoDienThoai_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSoDienThoai.KeyPress
        If Not (Char.IsDigit(e.KeyChar) Or Char.IsControl(e.KeyChar)) Then
            e.Handled = True
        End If
    End Sub
End Class